#!/bin/bash  

# 指定YAML文件路径
# yaml_file="/home/wzq/Music/workspace/src/control_policy/control_policy/MVS/Configs/InitConfigs.yaml"

function terminate_processes() {
    echo "Terminating all processes..."
    kill -TERM 0 # 发送TERM信号给所有的子进程
}

# 使用trap命令来捕获SIGINT信号
trap terminate_processes SIGINT

# 定义要启动的程序列表  
PROGRAMS=("../Decision.py" "../DataServer.py" "../MVS.py"  )  # 

# 遍历程序列表并启动每个程序  
for PROGRAM in "${PROGRAMS[@]}"; do  
    # 启动程序，并在后台运行  
    echo "Starting $PROGRAM ..."
    (python3 "$PROGRAM")  &
    
    # 可选：等待一段时间以确保程序已启动  
    sleep 1  
done  

# DECISION="../Decision.py"

# for ((i=0; i<$(yq e '.vehicle_cfg.num' $yaml_file ); i++)); do
#     # echo "Starting $DECISION ..."
#     (python3 "$DECISION" $i) &
#     # sleep 1
# done
  
# 等待所有子进程完成
wait

echo "All processes have finished."